home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / quartz / quartz10.lha / src / presto / stack.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-02  |  1.6 KB  |  56 lines

  1. //
  2. // Stack maintenance
  3. //
  4. // Modification History:
  5. //
  6. //   05-Dec-89  John Faust
  7. //   Remove all stack free lists.  Allocate stacks of fixed size when thread
  8. //   is allocated.  Stack remains associated with owning thread.  More
  9. //   efficient (removes search of stack freelist for stack of proper size,
  10. //   allocation of stack if one of proper size not found, and eliminates
  11. //   need to balance stack freelists).
  12. //
  13. //   16-Nov-1989  John Faust
  14. //   Add support for per-processor stack freelists.
  15. //
  16.  
  17. #define MINSTACKSIZEXP  (10)
  18. #define ONEK            (1<<10)
  19. //#define DEFSTACKSIZ   (ONEK << 2)                     /* 4k */
  20. //#define DEFSTACKSIZ   (ONEK << 3)                     /* 8k */
  21. #define DEFSTACKSIZ     (ONEK << 4)                     /* 16k */
  22.  
  23. //
  24. // Return how many integral chunks of MINSTACKSIZES fit in the 
  25. // requested stacksize
  26. //
  27. //#define STACKSIZTOMINCHUNKS(sz)    (sz >> MINSTACKSIZEXP)
  28.  
  29. class Stack    {
  30.     int *st_base;        // bottom of stack
  31.     int st_size;        // what user thinks
  32.     int st_limit;        // what we really are
  33. public:
  34.     Stack(int size);
  35.         inline ~Stack()
  36.                 { this->destroy (); }
  37.         inline int size()
  38.                 { return st_size; }
  39.         inline int limit()
  40.                 { return st_limit;}
  41. /* XX machdep */        
  42.     inline int *top()
  43.         { return  (int*)(((int)st_base + st_limit - 4) & ~03);}
  44.     inline void destroy()
  45.         { delete st_base; }
  46.  
  47.         //
  48.         // Disabled.  Stacks only built when threads are allocated, and
  49.         // incrementing a counter atomically on the critical path is too slow.
  50.         // Returns -1.
  51.         //
  52.     int numstacksbuilt();
  53. };
  54.  
  55.  
  56.